<script>
	import Vue from 'vue'
	export default {
		onLaunch() {
			// 获取店铺配置信息  全局只请求一次
			this.$api.shopConfig(res => {
				this.$store.commit('config', res.data)
			})
			// #ifdef APP-PLUS || APP-PLUS-NVUE
			this.checkVersion()
			// #endif
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif
			
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		
			
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})
		},
		onShow: function() {
			//console.log('App Show')
		},
		onHide: function() {
			//console.log('App Hide')
		},
		methods: {
			// #ifdef APP-PLUS || APP-PLUS-NVUE
			// app更新检测
			checkVersion() {
				// 获取应用版本号
				let version = plus.runtime.version;

				//检测当前平台，如果是安卓则启动安卓更新
				uni.getSystemInfo({
					success: res => {
						this.updateHandler(res.platform, version);
					}
				})
			}, 
			// 更新操作
			updateHandler(platform, version) {
				let data = {
					platform: platform,
					version: version
				}
				let _this = this; 
				this.$api.getAppVersion(data,res => { 
						if (res.status) {
							let info = res.data;
							if(info.version == '') {
								return;
							}; 
							let newver = _this.toNum(info.version);
							let currver = _this.toNum(version);
							if (newver > currver) { 
								uni.showModal({
									//提醒用户更新
									title: '更新提示',
									content: info.content,
									success: res => {
										if (res.confirm) {
											plus.runtime.openURL(info.downurl)
										}
									}
								})
							}
						}
					}
				)
			},			
			toNum(a){
				var a=a.toString();
				//也可以这样写 var c=a.split(/\./);
				var c=a.split('.');
				var num_place=["","0","00","000","0000"],r=num_place.reverse();
				for (var i=0;i<c.length;i++){ 
					var len=c[i].length;       
					c[i]=r[len]+c[i];  
				} 
				var res= c.join(''); 
				return res; 
			}				
			// #endif
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import './static/css/style.css';
	@import './static/css/style.scss';
	@import './static/css/base.css';
    @import '/static/iconfont/iconfont.css';
	@import url("/components/gaoyia-parse/parse.css");
	@import url("@/plugin/animate/animate.min.css");
	@import 'static/css/guildford.css';
	@import "./static/colorui/main.css";
	@import "./static/colorui/icon.css";
	.bgf {
		background: #FFF;
	}

	.flc {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.flc-inline {
		display: inline-flex;
		align-items: center;
	}

	.g5 {
		color: $g5;
	}

	.fz12 {
		font-size: $fz12;
	}
	view {
		box-sizing: border-box;
	}
	
	.bg-color-red {
		background-color: #ff5400 !important;
	}
	
	.syspadding {
		padding-top: var(--status-bar-height);
	}
	
	.flex {
		display: flex;
	}
	
	.uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none
	}
	
	::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
	}
	::-moz-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
	}
	
	.empty-txt {
		line-height: 100rpx;
		font-size: 22rpx;
		color: #999;
		text-align: center;
	}
	.product-con .conter img{
		display: block;
	}
</style>
